package com.taxi.driver.data.order.remote;

import com.taxi.driver.api.OrderApi;
import com.taxi.driver.config.DriverType;
import com.taxi.driver.data.entity.CanGrapOrdersEntity;
import com.taxi.driver.data.entity.CancelDesEntity;
import com.taxi.driver.data.entity.ComplainResultEntity;
import com.taxi.driver.data.entity.OrderCostEntity;
import com.taxi.driver.data.entity.OrderEntity;
import com.taxi.driver.data.entity.OrderHomeStatusEntity;
import com.taxi.driver.data.entity.OrderSummaryEntity;
import com.taxi.driver.data.entity.WaitFare;
import com.taxi.driver.data.entity.WxpayInfo;
import com.taxi.driver.data.order.OrderSource;
import com.taxi.driver.data.user.UserRepository;

import java.util.List;

import javax.inject.Inject;

import rx.Observable;

/**
 * 功能描述：
 */
public class OrderRemoteSource implements OrderSource {

    private OrderApi mOrderApi;
    private UserRepository mUserRepository;

    @Inject
    public OrderRemoteSource(OrderApi orderApi, UserRepository userRepository) {
        mOrderApi = orderApi;
        mUserRepository = userRepository;
    }

    /**
     * 特别注意：
     * 根据司机类型，切换订单相关接口
     * 在OrderApi中有使用到
     */
    private String getApiPath() {
        if (mUserRepository.getDriverType() == DriverType.SPECIAL) {//专车司机
            return "specialOrder";
        }
        return "";
    }

    @Override
    public void cacheOrder(OrderEntity entity) {
    }

    @Override
    public Observable<OrderHomeStatusEntity> reqHomeStatus() {
        return mOrderApi.reqHomeStatus(getApiPath());
    }

    @Override
    public Observable<List<OrderSummaryEntity>> reqOrderList(int nowPage) {
        return mOrderApi.reqOrderList(getApiPath(), nowPage);
    }

    @Override
    public Observable<OrderEntity> reqGrab(String orderUuid) {
        return mOrderApi.reqGrab(getApiPath(), orderUuid);
    }

    @Override
    public Observable<OrderEntity> reqOrderDetail(String orderUuid) {
        return mOrderApi.reqOrderDetail(getApiPath(), orderUuid);
    }

    @Override
    public Observable<OrderEntity> reqOrderDetail(String orderUuid, boolean onlyFromRemote) {
        return reqOrderDetail(orderUuid);
    }

    @Override
    public Observable<String> reqPickUpPas(String orderUuid, String uploadText) {
        return mOrderApi.reqPickUpPas(getApiPath(), orderUuid, uploadText);
    }

    @Override
    public Observable<String> reqDepart(String orderUuid, String uploadText) {
        return mOrderApi.reqDepart(getApiPath(), orderUuid, uploadText);
    }

    @Override
    public Observable<String> reqGetOn(String orderUuid, double waitMile, String uploadText) {
        return mOrderApi.reqGetOn(getApiPath(), orderUuid, waitMile, uploadText);
    }

    @Override
    public Observable<String> reqArrive(String orderUuid, double tripDistance, String destAddress,
                                        String destDetailAddress, String destCity, double destLng,
                                        double destLat, String uploadText) {
        return mOrderApi.reqArrive(getApiPath(), orderUuid, tripDistance,
                destAddress, destDetailAddress, destCity,
                destLng, destLat, uploadText);
    }

    @Override
    public Observable<String> reqUpdateFare(String orderUuid, double actualFare) {
        return mOrderApi.reqUpdateFare(getApiPath(), orderUuid, actualFare);
    }

    @Override
    public Observable<String> receiveCash(String orderUuid, String uploadText) {
        return mOrderApi.receiveCash(orderUuid, uploadText);
    }

    @Override
    public Observable<String> reqCancelOrder(String orderUuid, String cancelMsg, String uploadText) {
        return mOrderApi.cancelOrder(orderUuid, cancelMsg, uploadText);
    }

    @Override
    public Observable<String> reqComplainOrder(String orderUuid, String contents, String remark) {
        return mOrderApi.complainOrder(orderUuid, contents, remark);
    }

    @Override
    public Observable<String> rushFare(String orderUuid) {
        return mOrderApi.rushFare(orderUuid);
    }

    @Override
    public Observable<ComplainResultEntity> isComplain(String orderUuid) {
        return mOrderApi.isComplain(orderUuid);
    }

    @Override
    public Observable<CancelDesEntity> cancelDescription(String orderUuid) {
        return mOrderApi.cancelDescription(orderUuid);
    }

    @Override
    public Observable<WxpayInfo> payByWechat(String orderUuid, String spbillCreateIp) {
        return mOrderApi.payByWechat(orderUuid, spbillCreateIp);
    }

    @Override
    public Observable<String> payByAlipay(String orderUuid) {
        return mOrderApi.payByAlipay(orderUuid);
    }

    @Override
    public Observable<String> payByBalance(String orderUuid) {
        return mOrderApi.payByBalance(orderUuid);
    }

    @Override
    public Observable<OrderCostEntity> reqFareItems(String orderUuid) {
        return mOrderApi.fareItems(orderUuid);
    }

    @Override
    public Observable<OrderCostEntity> getRealtimeFare(String orderUuid) {
        return mOrderApi.getRealtimeFare(orderUuid);
    }

    @Override
    public Observable<OrderCostEntity> orderFare(String orderUuid) {
        return mOrderApi.orderFare(orderUuid);
    }

    @Override
    public Observable<String> confirmFare(String orderUuid, Integer highwayFare, Integer roadBridgeFare,
                                          Integer otherFare, String uploadText) {
        return mOrderApi.confirmFare(orderUuid, highwayFare, roadBridgeFare, otherFare, uploadText);
    }

    @Override
    public Observable<WaitFare> waitFare(String orderUuid) {
        return mOrderApi.waitFare(orderUuid);
    }

    @Override
    public Observable<List<OrderSummaryEntity>> getAppointmentList() {
        return mOrderApi.getAppointmentList();
    }

    @Override
    public Observable<CanGrapOrdersEntity> canGrapOrders(String areaCode) {
        return mOrderApi.canGrapOrders(areaCode);
    }

    @Override
    public Observable<List<OrderSummaryEntity>> getOrderPool(String areaCode) {
        return mOrderApi.getOrderPool(areaCode);
    }

    @Override
    public void ignoringOrder(String orderUuid) {

    }

    @Override
    public Observable<List<String>> ignoreList() {
        return null;
    }
}
